

package com.mt.restaurant.controller.material;

import org.springframework.security.access.prepost.PreAuthorize;
import com.mt.common.core.annotation.ApiPageParam;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.mt.common.core.web.base.PageDTO;
import com.mt.common.core.web.base.PageResultDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;



import com.mt.restaurant.dto.material.StockRecordEditDto;
import com.mt.restaurant.entity.material.StockRecord;
import com.mt.restaurant.service.material.StockRecordService;
												

@Api(tags = "库存记录")
@RestController
@RequestMapping("/api/restaurant/material/StockRecord")
@CrossOrigin(allowCredentials = "true")
public class StockRecordController {
private static Logger logger = LoggerFactory.getLogger(StockRecordController.class);



																																							@Autowired private StockRecordService stockRecordService;
	
	/**
	* 根据分页参数查询库存记录集合
	*
	* @param pageDTO 分页条件
	*/
	@PreAuthorize("hasAuthority('restaurant:material:StockRecord:view')")
	@ApiOperation("分页查询库存记录")
	@ApiPageParam
	@PostMapping("/findStockRecords")
	public PageResultDTO findStockRecords(@RequestBody PageDTO pageDTO){
		return this.stockRecordService.findStockRecords(pageDTO);
	}

	/**
	* 根据ID查询指定的库存记录
	*
	* @param stockRecordId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:material:StockRecord:view')")
	@ApiOperation("根据id查询库存记录")
	@ApiPageParam
	@PostMapping("/findStockRecord")
	public StockRecord findStockRecord(@RequestParam Long stockRecordId){
		return this.stockRecordService.findStockRecord(stockRecordId);
	}

	/**
	* 根据ID查询指定的库存记录(包含外键名称)
	*
	* @param stockRecordId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:material:StockRecord:view')")
	@ApiOperation("根据ID查询指定的库存记录(包含外键名称)")
	@PostMapping("/findStockRecordForView")
	public StockRecord findStockRecordForView(@RequestParam Long stockRecordId){
		return this.stockRecordService.findStockRecordWithForeignName(stockRecordId);
	}

	/**
	* 根据ID查询指定的库存记录(包含库存记录和外键名称)
	*
	* @param stockRecordId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:material:StockRecord:view')")
	@ApiOperation("根据ID查询指定的库存记录(包含库存记录和外键名称)")
	@PostMapping("/findStockRecordForEdit")
	public StockRecordEditDto findStockRecordForEdit(@RequestParam Long stockRecordId){
				StockRecordEditDto stockRecordEditDto = new StockRecordEditDto();
		stockRecordEditDto.setStockRecord(this.stockRecordService.findStockRecordWithForeignName(stockRecordId));

		this.prepareStockRecordEditDto(stockRecordEditDto);

		return stockRecordEditDto;
	}

	/**
	* 根据ID查询指定的库存记录(只提取ID 和 Name)
	*
	* @param stockRecordId Id
	*/
	@PreAuthorize("hasAuthority('restaurant:material:StockRecord:view')")
	@ApiOperation("根据ID查询指定的库存记录(只提取ID 和 Name)")
	@PostMapping("/findStockRecordsWithIdNameById")
	public StockRecord findStockRecordsWithIdNameById(@RequestParam Long stockRecordId){
	return this.stockRecordService.findStockRecordsWithIdNameById(stockRecordId);
	}

	/**
	* 根据名称查询库存记录集合(只提取ID 和 Name)
	*
	* @param stockRecordName 名称
	*/
	@PreAuthorize("hasAuthority('restaurant:material:StockRecord:view')")
	@ApiOperation("根据名称查询库存记录集合(只提取ID 和 Name)")
	@PostMapping("/findStockRecordsWithIdNameByName")
	public List<StockRecord> findStockRecordsWithIdNameByName(@RequestParam String stockRecordName){
	return this.stockRecordService.findStockRecordsWithIdNameByName(stockRecordName);
	}


	/**
	* 创建新的库存记录
	*
	*/
	@PreAuthorize("hasAuthority('restaurant:material:StockRecord:add')")
	@ApiOperation("创建新的库存记录")
	@PostMapping("/createStockRecord")
	public StockRecordEditDto createStockRecord(){
				StockRecordEditDto stockRecordEditDto = new StockRecordEditDto();
		stockRecordEditDto.setStockRecord(new StockRecord());

		this.prepareStockRecordEditDto(stockRecordEditDto);
		return stockRecordEditDto;
	}

	private void prepareStockRecordEditDto(StockRecordEditDto stockRecordEditDto){
																																						}

	/**
	* 新增保存库存记录
	*
	* @param stockRecord 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:material:StockRecord:add')")
	@ApiOperation("新增保存库存记录")
	@PostMapping("/saveStockRecord")
	public StockRecord saveStockRecord(@RequestBody StockRecord stockRecord){
		return this.stockRecordService.saveStockRecord(stockRecord);
	}

	/**
	* 修改保存库存记录
	*
	* @param stockRecord 实体对象
	*/
	@PreAuthorize("hasAuthority('restaurant:material:StockRecord:update')")
	@ApiOperation("修改保存库存记录")
	@PostMapping("/updateStockRecord")
	public StockRecord updateStockRecord(@RequestBody StockRecord stockRecord){
		return this.stockRecordService.updateStockRecord(stockRecord);
	}

	/**
	* 根据ID删除库存记录
	*
	* @param stockRecordId ID
	*/
	@PreAuthorize("hasAuthority('restaurant:material:StockRecord:remove')")
	@ApiOperation("根据ID删除库存记录")
	@PostMapping("/deleteStockRecord")
	public void deleteStockRecord(@RequestParam Long stockRecordId){
		this.stockRecordService.deleteStockRecord(stockRecordId);
	}



}

